package sanshui.system.trade.common;

import lombok.Data;

@Data
public class CommonResponse<T> {
    int code;
    T data;
    String message;

    public static CommonResponse<Object> ok(){
        CommonResponse<Object> resposne = new CommonResponse<>();
        resposne.setCode(200);
        resposne.setMessage("执行成功");
        resposne.setData(null);
        return resposne;
    }

    public static <T> CommonResponse<T> ok(T data){
        CommonResponse<T> resposne = new CommonResponse<>();
        resposne.setCode(200);
        resposne.setMessage("执行成功");
        resposne.setData(data);
        return resposne;
    }

    public static <T> CommonResponse<T> ok(T data, String message){
        CommonResponse<T> resposne = new CommonResponse<>();
        resposne.setCode(200);
        resposne.setMessage(message);
        resposne.setData(data);
        return resposne;
    }

    public static CommonResponse<Object> err(){
        CommonResponse<Object> resposne = new CommonResponse<>();
        resposne.setCode(500);
        resposne.setMessage("执行失败");
        resposne.setData(null);
        return resposne;
    }

    public static CommonResponse<Object> err(String message){
        CommonResponse<Object> resposne = new CommonResponse<>();
        resposne.setCode(500);
        resposne.setMessage(message);
        resposne.setData(null);
        return resposne;
    }

    public static <T> CommonResponse<T> err(T data, String message){
        CommonResponse<T> resposne = new CommonResponse<>();
        resposne.setCode(500);
        resposne.setMessage(message);
        resposne.setData(data);
        return resposne;
    }
}
